package 密码学实验;

import java.util.Random;

public class LinearCongruential {
    private long seed;

    public LinearCongruential() {
        srand(System.currentTimeMillis());
    }

    public void srand(long s) {
        seed = s;
    }

    public int rand() {
        // X_{n+1} = (a * X_n + c) mod m
        seed = (seed * 31 + 13) % ((1 << 15) - 1);
        return (int) seed;
    }

    public static void main(String[] args) {
        LinearCongruential rng = new LinearCongruential();
        System.out.println("生成0-100的随机数:");
        for (int i = 0; i < 10; i++) {
            System.out.print(rng.rand() % 100 + " ");
        }
    }
}